package kafka_producer.controller;

import java.io.IOException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import kafka_producer.entity.ProducerEntity;
import kafka_producer.service.ProducerService;
import kafka_producer.util.ProducerUtil;
import com.alibaba.fastjson.JSON;

@RestController
@RequestMapping(value = "/api")
public class ProducerController {
	@Autowired
	private ProducerService producerService;
	@Autowired 
	private ProducerUtil producerUtil;
	@GetMapping(value = "/producer")
	public ProducerEntity selectController(@RequestParam(value = "name",required = true) String name) throws IOException{
		System.out.println("开始查询信息……");
		ProducerEntity result=producerService.selectService(name);
		String jsonResult=JSON.toJSONString(result);
		producerUtil.send("kafka-YL", jsonResult);
		return result;
	}
}
